#coding=utf-8

import urllib2


#本文件是在python2中运行,如是在python3中运行,则将urllib2改为urllib.request

def send_request():
    #发送指定的url地址请求,返回一个类文件的响应对象
    response = urllib2.urlopen('http://www.baidu.com/')
    #读取响应中内容,获取网页原始编码字符串
    html = response.read()
    return html


if __name__ == '__main__':
    html = send_request()
    #print(html.decode('utf-8'))  # 表名html是utf-8字符串
    #print(type(html))
    #print(html)  #这里是字符串,python2写入采用w或者wb都行
    with open('baidu.html', 'w') as f:
        f.write(html)

